package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Employeetransaction;
import com.restaurant.service.EmployeetransactionService;

public class EmployeetransactionServiceImpl implements EmployeetransactionService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeetransaction addOrModify( Employeetransaction objEmployeetransaction ) {
       return ( Employeetransaction ) hibernateTemplate.merge( objEmployeetransaction );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeetransaction deleteRecord( Employeetransaction objEmployeetransaction ) {
       hibernateTemplate.delete( objEmployeetransaction );
       return objEmployeetransaction;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeetransaction modifyRecord( Employeetransaction objEmployeetransaction ) {
       return ( Employeetransaction ) hibernateTemplate.merge( objEmployeetransaction );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Employeetransaction> loadAll() {
       return (List<Employeetransaction>)hibernateTemplate.findByNamedQuery( "Employeetransaction.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeetransaction loadByPrimaryKey( Long primaryKey ) {
       return (Employeetransaction) hibernateTemplate.get( Employeetransaction.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeetransaction deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Employeetransaction> loadByHql(String query) {
       return ( List<Employeetransaction> ) hibernateTemplate.find( query );
   }
}